package com.tianji.learning.controller;


import com.tianji.common.domain.dto.PageDTO;
import com.tianji.learning.domain.po.Note;
import com.tianji.learning.domain.query.NoteQuery;
import com.tianji.learning.service.INoteService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;
import org.checkerframework.checker.units.qual.A;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;

import org.springframework.web.bind.annotation.RestController;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author yb0os1
 * @since 2025-03-31
 */
@Api("用户端笔记相关接口")
@RestController
@RequestMapping("/notes")
@RequiredArgsConstructor
public class NoteController {
    private final INoteService noteService;
    @ApiOperation("新增笔记")
    @PostMapping
    public void saveNote(@RequestBody Note note){
        noteService.saveNote(note);
    }
    @ApiOperation("采集笔记")
    @PostMapping("/gathers/{id}")
    public void gatherNote(@PathVariable("id") Integer id){
        noteService.gatherOrCancelNote(id, true);
    }

    @ApiOperation("取消采集笔记")
    @DeleteMapping("/gathers/{id}")
    public void cancelGatherNote(@PathVariable("id") Integer id){
        noteService.gatherOrCancelNote(id, false);
    }
    @ApiOperation("编辑笔记")
    @PutMapping("/{id}")
    public void updateNote(@PathVariable("id") Integer id,  Note note){
        noteService.updateNote(id,note);
    }

    @ApiOperation("删除笔记")
    @DeleteMapping("/{id}")
    public void deleteNote(@PathVariable("id") Integer id){
        noteService.deleteNote(id);
    }

    @ApiOperation("用户端分页查询笔记")
    @GetMapping("/page")
    public PageDTO pageQueryNotes(NoteQuery query){
        return noteService.pageQueryNotes(query);
    }
}
